package com.tarena.csmall.sso.controller;

import cn.tedu.mall.common.restful.JsonResult;
import com.tarena.csmall.sso.pojo.vo.TokenVO;
import com.tarena.csmall.sso.service.IPhoneService;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sso/sms")
public class PhoneController {
    @Autowired
    private IPhoneService phoneService;
    /**
     * 给手机号发送短信
     */
    @GetMapping("/send/code")
    public JsonResult sendCode(String phone){
        phoneService.sendCode(phone);
        return JsonResult.ok();
    }
    /**
     * 登录同时注册 默认身份的用户信息
     * 让用户登录之后修改个人详情
     */
    @GetMapping("/login")
    public JsonResult<TokenVO> doLogin(String phone,String code){
        String token=phoneService.loginWithCode(phone,code);
        TokenVO tokenVO=new TokenVO();
        tokenVO.setTokenValue(token);
        tokenVO.setTokenHeader("Bearer");
        return JsonResult.ok(tokenVO);
    }
}
